<%@page import="dao.pageDAO"%>
<%@page import="entity.usePage"%>
<%@page import="entity.PageConfig"%>
<%@page import="entity.student"%>
<%@page import="java.util.List"%>
<%@page import="dao.studentDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Insert title here</title>
		<link rel="stylesheet" type="text/css" href="css/txl.css"/>
		<style type="text/css">
			html,body{
				text-align: center;
			}
		</style>
	</head>
	<body id="mybody">
	<center>
		<table border="0" cellspacing="0" cellpadding="" id="mytable">
			<caption>
				软件2015级学生通讯录
			</caption>
			<tr>
				<th>编号</th>
				<th>姓名</th>
				<th>性别</th>
				<th>地址</th>
				<th>电话号码</th>
				<th>邮箱</th>
				<th>操作</th>
			</tr> 

		<%
			usePage p =(usePage)request.getAttribute("page");
			if(p==null){
				p = new usePage();
			}
		%>
		
		<%
			pageDAO pagedao = new pageDAO();
			List<student> list = pagedao.getAllStudents_page(p);
			studentDAO studentdao = new studentDAO();
			List<student> list2 = studentdao.getAllStudents_page();
			List<student> list1 = studentdao.getAllStudents();
			int cnt = list1.size();
			if(list!=null&&list.size()>0)
			{
				for(int i=0;i<list.size();i++)
				{
					student stu  = list.get(i);
					if((i+1)%2!=0)
					{
		%>
			<tr>
			
				<th scope="row" abbr="Model" class="srec"><%=stu.getId() %></th>
				<td><%=stu.getName() %></td>
				<td><%=stu.getSex() %></td>
				<td><%=stu.getAddress() %></td>
				<td><%=stu.getPhone() %></td>
				<td><%=stu.getEmail() %></td>
				<td class="alt"><a href="<%=request.getContextPath()%>/deleteServlet?id=<%=stu.getId()%>">删除</a><span>|</span><a href="update.jsp?id=<%=stu.getId()%>">修改</a></td>
			</tr>
		<%
					}
					if((i+1)%2==0)
					{
		%>
			<tr>
				<th scope="row" abbr="G5 Processor" class="srecalt"><%=stu.getId() %></th>
				<td class="alt"><%=stu.getName() %></td>
				<td class="alt"><%=stu.getSex() %></td>
				<td class="alt"><%=stu.getAddress() %></td>
				<td class="alt"><%=stu.getPhone() %></td>
				<td class="alt"><%=stu.getEmail() %></td>
				<td class="alt"><a href="<%=request.getContextPath()%>/deleteServlet?id=<%=stu.getId()%>">删除</a><span>|</span><a href="update.jsp?id=<%=stu.getId()%>">修改</a></td>
			</tr>
		<%
					}	
		%>
		<%
				}
		%>
			<tr>
				<td colspan="7"><a href="add.jsp">添加一行记录</a></td>
			</tr>
		</table>
	</center>
		<hr>
		<div class="total" align="center"><span id="total">总记录数：<%=cnt%>条</span></div>
		<%
			}
		%>
		
		<%
			PageConfig pc =(PageConfig)request.getAttribute("page2");
			if(pc==null){
				pc = new PageConfig();
			}
			int totalpage=pc.getPageCount(cnt, pc.getPageSize());
		%>
		<div class="page">
			<a href = "<%=request.getContextPath() %>/pageServlet?currentPage=1&&method=first" >首页</a>  
			<a href = "<%=request.getContextPath() %>/pageServlet?currentPage=<%=pc.getCurrentPage()-1 %>&&method=prev" >上一页</a>  
			<a href = "<%=request.getContextPath() %>/pageServlet?currentPage=<%=pc.getCurrentPage()+1 %>&&method=next" >下一页</a>  
			<a href = "<%=request.getContextPath() %>/pageServlet?currentPage=4&&method=last" >尾页</a>  
			第<%=pc.getCurrentPage() %>页/共<%=totalpage %>页  
		</div>
	</body>
</html>